package com.ruoyi.be.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.be.domain.MyMedicalOutpatientdoctorReceiverecord;
import com.ruoyi.be.service.IMyMedicalOutpatientdoctorReceiverecordService;
import com.ruoyi.common.utils.uuid.IdUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.be.domain.MyMedicalCpoeSplitbed;
import com.ruoyi.be.service.IMyMedicalCpoeSplitbedService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 分床记录Controller
 * 
 * @author ly
 * @date 2022-01-05
 */
@RestController
@RequestMapping("/be/splitbed")
public class MyMedicalCpoeSplitbedController extends BaseController
{
    @Autowired
    private IMyMedicalCpoeSplitbedService myMedicalCpoeSplitbedService;
    @Autowired
    private IMyMedicalOutpatientdoctorReceiverecordService myMedicalOutpatientdoctorReceiverecordService;

    /**
     * 查询分床记录列表
     */
    @PreAuthorize("@ss.hasPermi('be:splitbed:list')")
    @GetMapping("/list")
    public TableDataInfo list(MyMedicalCpoeSplitbed myMedicalCpoeSplitbed)
    {
        startPage();
        List<MyMedicalCpoeSplitbed> list = myMedicalCpoeSplitbedService.selectMyMedicalCpoeSplitbedList(myMedicalCpoeSplitbed);
        return getDataTable(list);
    }

    /**
     * 导出分床记录列表
     */
    @PreAuthorize("@ss.hasPermi('be:splitbed:export')")
    @Log(title = "分床记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MyMedicalCpoeSplitbed myMedicalCpoeSplitbed)
    {
        List<MyMedicalCpoeSplitbed> list = myMedicalCpoeSplitbedService.selectMyMedicalCpoeSplitbedList(myMedicalCpoeSplitbed);
        ExcelUtil<MyMedicalCpoeSplitbed> util = new ExcelUtil<MyMedicalCpoeSplitbed>(MyMedicalCpoeSplitbed.class);
        util.exportExcel(response, list, "分床记录数据");
    }

    /**
     * 获取分床记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('be:splitbed:query')")
    @GetMapping(value = "/splitbed/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        System.out.println("我竟来了");
        return AjaxResult.success(myMedicalCpoeSplitbedService.selectMyMedicalCpoeSplitbedById(id));
    }
    @PreAuthorize("@ss.hasPermi('be:splitbed:query')")
    @GetMapping(value = "/{bedId}")
    public AjaxResult getr(@PathVariable("bedId") String bedId)
    {
        return AjaxResult.success(myMedicalCpoeSplitbedService.selectMyMedicalCpoeSplitbedbybedId(bedId));
    }

    /**
     * 新增分床记录
     */
    @PreAuthorize("@ss.hasPermi('be:splitbed:add')")
    @Log(title = "分床记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyMedicalCpoeSplitbed myMedicalCpoeSplitbed)
    {
        System.out.println(myMedicalCpoeSplitbed);
        myMedicalCpoeSplitbed.setId(IdUtils.fastUUID().substring(0,6));
        myMedicalCpoeSplitbed.setCreateTime(new Date());
        MyMedicalOutpatientdoctorReceiverecord myMedicalOutpatientdoctorReceiverecord = new MyMedicalOutpatientdoctorReceiverecord();
        myMedicalOutpatientdoctorReceiverecord.setSid(myMedicalCpoeSplitbed.getSid());
        int i = myMedicalCpoeSplitbedService.insertMyMedicalCpoeSplitbed(myMedicalCpoeSplitbed);
        if(i>0){
            myMedicalOutpatientdoctorReceiverecordService.updateMyMedicalOutpatientdoctorReceiverecordUpdate(myMedicalOutpatientdoctorReceiverecord);
        }
        AjaxResult ajaxResult = toAjax(i);
        return ajaxResult;
    }

    /**
     * 修改分床记录
     */
    @PreAuthorize("@ss.hasPermi('be:splitbed:edit')")
    @Log(title = "分床记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyMedicalCpoeSplitbed myMedicalCpoeSplitbed)
    {
        return toAjax(myMedicalCpoeSplitbedService.updateMyMedicalCpoeSplitbed(myMedicalCpoeSplitbed));
    }

    /**
     * 删除分床记录
     */
    @PreAuthorize("@ss.hasPermi('be:splitbed:remove')")
    @Log(title = "分床记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(myMedicalCpoeSplitbedService.deleteMyMedicalCpoeSplitbedByIds(ids));
    }
}
